package cn.bluethink.eguan.trader.controller;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.bluethink.eguan.core.security.Token;
import cn.bluethink.eguan.core.service.EgFactionService;
import cn.bluethink.eguan.core.service.EgGoodsHistoryService;
import cn.bluethink.eguan.core.service.EgGoodsService;
import cn.bluethink.eguan.core.service.EgUserService;
import cn.bluethink.eguan.filter.GoodsFilter;
import cn.bluethink.eguan.filter.IDFilter;
import cn.bluethink.eguan.model.core.EgBag;
import cn.bluethink.eguan.model.core.EgConfigInfo;
import cn.bluethink.eguan.model.core.EgGoods;
import cn.bluethink.eguan.model.core.EgGoodsStatus;
import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.core.EgPurview;
import cn.bluethink.eguan.model.core.EgRole;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.model.trader.EgTrader;
import cn.bluethink.eguan.model.trader.EgTraderStatus;
import cn.bluethink.eguan.result.PageInfo;
import cn.bluethink.eguan.result.ResponseMessage;
import cn.bluethink.eguan.result.ResponseResult;
import cn.bluethink.eguan.trader.filter.TraderFilter;
import cn.bluethink.eguan.trader.service.EgTraderService;
import cn.bluethink.eguan.utils.DateUtil;

/**
 * 神秘商人控制器
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.3.0
 * @brief 驿馆+产品
 * @note 修订历史： 1.wanglei于2018/11/26设计并构建初始版本v0.3.0
 */
@CrossOrigin
@RestController
@RequestMapping("/eguan/v1.0/trader")
public class EgTraderController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private EgTraderService traderService;

    @Autowired
    private EgUserService userService;

    @Autowired
    private EgFactionService factionService;

    @Autowired
    private EgGoodsService goodsService;

    @Autowired
    private EgGoodsHistoryService goodsHistoryService;

    @Autowired
    private EgConfigInfo configInfo;

    /**
     * 创建神秘商人（截止时间、委托人(非必填)、服务费（暂时不考虑））
     * 
     * @param trader
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @PostMapping("/create")
    public ResponseResult<EgTrader> create(@RequestBody EgTrader trader) throws Exception {
        // 获取商人隶属的位置(默认为江湖)
        Long fid = (trader.getFid() == null || trader.getFid() < 0) ? 0L : trader.getFid();
        // 获取委托者(一个用户只能扮演一个神秘商人),如果指定了委托人（非必填）
        EgObject actor = trader.getActor();
        if (actor != null && actor.getId() != null && actor.getId() > 0) {
            // 判断该用户在该神秘商人隶属的位置是否正在扮演商人
            if (traderService.getTraderByActorAndFid(actor.getId(), fid) != null) {
                return new ResponseResult<>(ResponseMessage.CREATE_FAIL.getStatus(), "该委托人正在扮演神秘商人！");
            }
        }
        // 请求的截止时间不能为空(必填项)
        if (trader.getEtime() == null) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_CONTENT.getStatus(), "截止时间不能为空！");
        }
        // 设置创建者
        Long uid = (Long) request.getAttribute("userId");
        trader.setCuser(new EgObject(uid, null, null));
        // 创建神秘商人
        EgTrader result = null;
        if (fid > 0) {
            // 获取门派账户信息，创建神秘商人，存入门派账户ID
            Long fAcount = factionService.getAcountByFid(fid);
            if (fAcount == 0L) {
                return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND.getStatus(), "门派账户不存在！");
            }
            result = traderService.create(trader, fAcount);
        } else {
            // 创建神秘商人，存入江湖账户ID
            result = traderService.create(trader, configInfo.getAcountId());
        }
        if (result != null) {
            return new ResponseResult<>(ResponseMessage.OK, result);
        }
        return new ResponseResult<>(ResponseMessage.CREATE_FAIL);
    }

    /**
     * 逻辑删除神秘商人(具有审核权限，均可删除神秘商人，不管神秘商人是谁创建的；否则需要判断是否是当前登录用户创建的)
     * 
     * @param id
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/del")
    public ResponseResult<Long> del(@RequestParam Long id) throws Exception {
        EgTrader trader = traderService.detail(id);
        if (trader == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        Long uid = (Long) request.getAttribute("userId");
        EgRole role = userService.mypurview(uid);
        Boolean result = null;
        // 如果当前登录用户为神秘商人创建者，或者拥有信息审核/商人管理权限，直接删除
        if (uid.equals(trader.getCuser().getId()) || (role != null && ((role.getPurview() & EgPurview.OBJECT_CHECK) > 0
                || (role.getPurview() & EgPurview.TRADER_MG) > 0))) {
            // 进行中的神秘商人，逻辑删除+转移操作，其他状态，只逻辑删除
            if (trader.getStatus().equals(EgTraderStatus.STATUS_HANDLE)) {
                result = traderService.transfer(trader, true, false);
            } else {
                result = traderService.del(id);
            }
        } else {
            return new ResponseResult<>(ResponseMessage.INADEQUATE_PERMISSIONS);
        }
        if (result != null && result) {
            return new ResponseResult<>(ResponseMessage.OK, id);
        }
        return new ResponseResult<>(ResponseMessage.DELETE_FAIL);
    }

    /**
     * 更新神秘商人信息(截止时间、委托人、状态) (具有商人管理权限，均可编辑神秘商人，不管神秘商人是谁创建的) 注意：神秘商人开始了也可以编辑委托者和截止时间
     * 
     * @param trader
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @PostMapping("/update")
    public ResponseResult<EgTrader> update(@RequestBody EgTrader trader) throws Exception {
        // 神秘商人ID不能为空
        if (trader.getId() == null || trader.getId() == 0) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_ID);
        }
        EgTrader oldTrader = traderService.detail(trader.getId());
        if (oldTrader == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 获取该商人的原委托者
        EgObject oldActor = oldTrader.getActor();
        // 获取该神秘商人隶属的位置
        Long fid = oldTrader.getFid();
        // 可以编辑委托者，但是不能为空
        EgObject actor = trader.getActor();
        if (oldActor == null && (actor == null || actor.getId() == null || actor.getId() == 0)) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_CONTENT.getStatus(), "委托者不能为空！");
        }
        if (actor != null && actor.getId() != null && actor.getId() > 0) {
            // 原委托者为空，被编辑的委托者已经在扮演神秘商人
            if (oldActor == null && traderService.getTraderByActorAndFid(actor.getId(), fid) != null) {
                return new ResponseResult<>(ResponseMessage.CREATE_FAIL.getStatus(), "该委托人正在扮演神秘商人！");
            }
            // 原委托者不为空，被更新的委托者不是原委托者(如果是，则其正在扮演)，并且更新的委托者已经在扮演神秘商人
            if (oldActor != null && !oldActor.getId().equals(actor.getId())
                    && traderService.getTraderByActorAndFid(actor.getId(), fid) != null) {
                return new ResponseResult<>(ResponseMessage.CREATE_FAIL.getStatus(), "该委托人正在扮演神秘商人！");
            }
        }
        // 获取该神秘商人的原状态以及待更新状态
        Integer oldStatus = oldTrader.getStatus();
        Integer upStatus = trader.getStatus();
        // 若更新的状态已存在，直接返回
        if (upStatus != null && oldStatus.equals(upStatus)) {
            return new ResponseResult<>(ResponseMessage.OK, oldTrader);
        }
        // 如果将原状态更新为【进行中】,未设置委托人，神秘商人无法开始
        if (upStatus != null && upStatus.equals(EgTraderStatus.STATUS_HANDLE)) {
            if (oldActor == null) {
                return new ResponseResult<>(ResponseMessage.UPDATE_FAIL.getStatus(), "未设置委托人，不能开始！");
            }
            oldTrader.setBtime(new Date());
            oldTrader.setStatus(EgTraderStatus.STATUS_HANDLE);
        }
        // 如果将原状态更新为【结束】，未兑换完的商品放入history表中
        if (upStatus != null && upStatus.equals(EgTraderStatus.STATUS_FINISH)) {
            oldTrader.setStatus(EgTraderStatus.STATUS_FINISH);
            if (!traderService.transfer(oldTrader, false, false)) {
                return new ResponseResult<>(ResponseMessage.UPDATE_FAIL);
            }
        }
        // 如果不是更新状态，结束的神秘商人，只能查看和删除，不能修改商人信息（截止时间，委托人，商品管理）
        if (upStatus == null && !oldStatus.equals(EgTraderStatus.STATUS_FINISH)) {
            // 编辑委托者
            if (actor != null && actor.getId() != null && actor.getId() > 0) {
                oldTrader.setActor(new EgObject(actor.getId(), null, null));
            }
            // 待更新的截至时间
            Date etime = trader.getEtime();
            if (etime != null && DateUtil.dateCompare(etime, oldTrader.getEtime()) != 0) {
                oldTrader.setEtime(DateUtil.dateTime(etime, 23, 59, 59));
            }
        }
        EgTrader result = traderService.update(oldTrader);
        if (result == null) {
            return new ResponseResult<>(ResponseMessage.UPDATE_FAIL);
        }
        return new ResponseResult<>(ResponseMessage.OK, result);
    }

    /**
     * 根据主键ID查看神秘商人详情
     * 
     * @param id
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @GetMapping("/detail")
    public ResponseResult<EgTrader> detail(@RequestParam Long id) throws Exception {
        EgTrader trader = traderService.detail(id);
        if (trader != null) {
            return new ResponseResult<>(ResponseMessage.OK, trader);
        }
        return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
    }

    /**
     * 判断工作台用户是否是神秘商人,是返回神秘商人的ID
     *
     * @param uid
     *            工作台用户ID
     * @param fid
     *            当前登录用户隶属的位置（门派ID/江湖ID）
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/judge")
    public ResponseResult<Long> judge(@RequestParam Long uid, @RequestParam Long fid) throws Exception {
        // 判断此工作台用户在当前门派/江湖，是否正在扮演神秘商人
        EgTrader trader = traderService.getTraderByActorAndFid(uid, fid);
        if (trader == null) {
            return new ResponseResult<>(ResponseMessage.OK, null);
        }
        // 如果神秘商人未开始，不显示神秘包裹
        if (!trader.getStatus().equals(EgTraderStatus.STATUS_HANDLE)) {
            return new ResponseResult<>(ResponseMessage.OK, null);
        }
        // 获取当前登录用户的信息
        Long loginUid = (Long) request.getAttribute("userId");
        EgUser loginUser = userService.getUser(loginUid, false);
        if (loginUser == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 获取委托者的信息
        EgUser actor = userService.getUser(uid, false);
        if (actor == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 判断当前用户和神秘商人委托者的位置是否相同
        if (!loginUser.getPos().equals(actor.getPos())) {
            return new ResponseResult<>(ResponseMessage.OK, null);
        }
        return new ResponseResult<>(ResponseMessage.OK, trader.getId());
    }

    /**
     * 根据过滤条件查询神秘商人列表。 1.按创建时间正序排序，展示未开始和进行中的神秘商人。
     * 2.在门派里只显示门派的神秘商人，在江湖里只显示江湖里的神秘商人（不包含门派里的神秘商人） 。
     * 3.查看商人记录（已结束，到了截止时间的定时将状态改为已结束）。
     * 
     * @param filter
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @PostMapping("/query")
    public ResponseResult<PageInfo<EgTrader>> query(@RequestBody TraderFilter filter) throws Exception {
        Long uid = (Long) request.getAttribute("userId");
        EgUser user = userService.getUser(uid, false);
        if (user == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        return new ResponseResult<>(ResponseMessage.OK, traderService.query(filter, user));
    }

    /**
     * 添加商品(标题、兑换价格、数量、图片)。 神秘商人一旦开始或者结束，就不能进行商品管理
     * 
     * @param goods
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @PostMapping("/creategoods")
    public ResponseResult<EgGoods> createGoods(@RequestBody EgGoods goods) throws Exception {
        Long uid = (Long) request.getAttribute("userId");
        // 获取请求的包裹信息
        EgBag bag = goods.getBag();
        if (bag == null || bag.getId() == null || bag.getId() == 0) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_ID.getStatus(), "包裹ID不能为空！");
        }
        // 商品的价格和数量必须大于0
        if (goods.getPrice() != null && goods.getPrice() <= 0) {
            return new ResponseResult<>(ResponseMessage.CREATE_FAIL.getStatus(), "商品的价格必须为正数！");
        }
        if (goods.getNumber() != null && goods.getNumber() <= 0) {
            return new ResponseResult<>(ResponseMessage.CREATE_FAIL.getStatus(), "商品的数量必须为正数！");
        }
        // 商品的名称长度不能超过64
        if (StringUtils.isNotBlank(goods.getName()) && goods.getName().length() > 64) {
            return new ResponseResult<>(ResponseMessage.CREATE_FAIL.getStatus(), "商品的名称超过限定长度！");
        }
        // 根据包裹ID获取神秘商人相关信息
        EgTrader trader = traderService.getTraderByBagId(bag.getId());
        if (trader == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 设置商品的剩余数量为添加商品的数量
        goods.setRemain(goods.getNumber());
        // 设置商品的所有者为神秘商人
        goods.setOwner(new EgObject(trader.getId(), null, new EgOType(EgOType.TRADER, null)));
        // 商人开始或结束，就不能进行商品管理
        if (!trader.getStatus().equals(EgTraderStatus.STATUS_NEW)) {
            return new ResponseResult<>(ResponseMessage.UPDATE_FAIL.getStatus(), "神秘商人已开始或者已结束，商品管理失败！");
        }
        // 创建神秘商品
        EgGoods result = traderService.createGoods(trader, goods, uid);
        if (result == null) {
            return new ResponseResult<>(ResponseMessage.CREATE_FAIL);
        }
        return new ResponseResult<>(ResponseMessage.OK, result);
    }

    /**
     * 删除商品,删除商品不影响商品兑换记录。 神秘商人一旦开始或者结束，就不能进行商品管理
     * 
     * @param gdid
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.OBJECT_CHECK, EgPurview.TRADER_MG })
    @PostMapping("/delgoods")
    public ResponseResult<Long> delGoods(@RequestParam Long gdid) throws Exception {
        // 获取商品的详情
        EgGoods goods = goodsService.detail(gdid);
        EgBag bag = goods.getBag();
        if (bag == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 根据包裹ID获取神秘商人相关信息
        EgTrader trader = traderService.getTraderByBagId(bag.getId());
        if (trader == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 商人开始或结束，就不能进行商品管理
        if (!trader.getStatus().equals(EgTraderStatus.STATUS_NEW)) {
            return new ResponseResult<>(ResponseMessage.UPDATE_FAIL.getStatus(), "神秘商人已开始或者已结束，商品管理失败！");
        }
        // 删除商品
        if (traderService.delGoods(trader, goods)) {
            return new ResponseResult<>(ResponseMessage.OK, gdid);
        }
        return new ResponseResult<>(ResponseMessage.DELETE_FAIL);
    }

    /**
     * 编辑商品(标题、兑换价格、数量、图片)。 神秘商人一旦开始或者结束，就不能进行商品管理
     * 
     * @param goods
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @PostMapping("/updategoods")
    public ResponseResult<EgGoods> updateGoods(@RequestBody EgGoods goods) throws Exception {
        // 商品的ID不能为空
        if (goods.getId() == null || goods.getId() == 0) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_ID);
        }
        // 获取商品的详情
        EgGoods oldGoods = goodsService.detail(goods.getId());
        EgBag bag = oldGoods.getBag();
        if (bag == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 根据包裹ID获取神秘商人相关信息
        EgTrader trader = traderService.getTraderByBagId(bag.getId());
        if (trader == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 商人开始或结束，就不能进行商品管理
        if (!trader.getStatus().equals(EgTraderStatus.STATUS_NEW)) {
            return new ResponseResult<>(ResponseMessage.UPDATE_FAIL.getStatus(), "神秘商人已开始或者已结束，商品管理失败！");
        }
        // 更新商品
        EgGoods result = traderService.updateGoods(trader, oldGoods, goods);
        if (result == null) {
            return new ResponseResult<>(ResponseMessage.UPDATE_FAIL);
        }
        return new ResponseResult<>(ResponseMessage.OK, result);
    }

    /**
     * 根据商品主键查询商品的详情
     * 
     * @param gdid
     * @return
     * @throws Exception
     */
    @Token
    @GetMapping("/detailgoods")
    public ResponseResult<EgGoods> detailGoods(Long gdid) throws Exception {
        // 获取商品的详情
        EgGoods goods = goodsService.detail(gdid);
        if (goods == null) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_ID);
        }
        return new ResponseResult<>(ResponseMessage.OK, goods);
    }

    /**
     * 兑换商品（这是消耗品，应该放到goods_history中）
     * 
     * @param goods
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/exchangegoods")
    public ResponseResult<EgGoods> exchangeGoods(@RequestBody EgGoods goods) throws Exception {
        // 请求的商品ID不能为空
        if (goods.getId() == null || goods.getId() == 0) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_ID);
        }
        // 获取当前兑换人的信息
        Long uid = (Long) request.getAttribute("userId");
        EgUser user = userService.getUser(uid, false);
        if (user == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 获取被兑换商品的详情
        EgGoods oldGoods = goodsService.detail(goods.getId());
        if (oldGoods == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 如果商品库存为0不能兑换
        if (oldGoods.getRemain() == 0) {
            return new ResponseResult<>(ResponseMessage.EXCHANGE_FAIL.getStatus(), "该商品库存不足，兑换失败！");
        }
        EgBag bag = oldGoods.getBag();
        if (bag == null || bag.getId() == null || bag.getId() == 0) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        Map<String, Long> traderMap = traderService.getTraderMapByBagId(bag.getId());
        if (traderMap == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 获取商人的ID/引用的账户ID
        Long traderId = traderMap.get("traderId");
        Long acountId = traderMap.get("acountId");
        // 神秘商人未开始或已结束或到截止时间不能兑换商品
        EgTrader oldTrader = traderService.detail(traderId);
        if (oldTrader == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        if (!oldTrader.getStatus().equals(EgTraderStatus.STATUS_HANDLE)
                || DateUtil.dateCompare(new Date(), oldTrader.getEtime()) > 0) {
            return new ResponseResult<>(ResponseMessage.EXCHANGE_FAIL.getStatus(), "神秘商人未开始或已结束，兑换失败！");
        }
        EgGoods result = traderService.exchange(oldGoods, goods, acountId, user, traderId);
        if (result == null) {
            return new ResponseResult<>(ResponseMessage.EXCHANGE_FAIL);
        }
        return new ResponseResult<>(ResponseMessage.OK, result);
    }

    /**
     * 兑换商品的派发
     * 
     * @param id
     * @return
     * @throws Exception
     */
    @Token(purviews = { EgPurview.TRADER_MG })
    @PostMapping("/distributegoods")
    public ResponseResult<EgGoods> distributeGoods(@RequestParam Long id) throws Exception {
        if (id == null || id == 0) {
            return new ResponseResult<>(ResponseMessage.NOTNULL_ID);
        }
        // 获取兑换的商品详情,以及状态
        EgGoods goodsHistory = goodsHistoryService.detail(id);
        if (goodsHistory == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        if (!goodsHistoryService.update(id)) {
            return new ResponseResult<>(ResponseMessage.UPDATE_FAIL);
        }
        goodsHistory.setStatus(EgGoodsStatus.STATUS_FINISH);
        goodsHistory.setUtime(new Date());
        return new ResponseResult<>(ResponseMessage.OK, goodsHistory);
    }

    /**
     * 过滤查询商品列表。 根据商品的所有者查询（神秘商人）
     * 
     * @param filter
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/querygoods")
    public ResponseResult<PageInfo<EgGoods>> queryGoods(@RequestBody IDFilter filter) throws Exception {
        return new ResponseResult<>(ResponseMessage.OK, goodsService.query(filter));
    }

    /**
     * 过滤查询兑换商品列表。
     * 1.所有神秘商人包裹中被兑换的商品列表，每条记录过滤owner_otype为神秘商人的情况(需要权限)
     * 2.我兑换的商品记录(无需权限)
     * 
     * @param filter
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/historygoods")
    public ResponseResult<PageInfo<EgGoods>> historyGoods(@RequestBody GoodsFilter filter) throws Exception {
        Long uid = (Long) request.getAttribute("userId");
        EgUser user = userService.getUser(uid, false);
        if (user == null) {
            return new ResponseResult<>(ResponseMessage.DATA_NOT_FOUND);
        }
        // 如果不是查看自己的兑换记录
        if (filter.getBmine() == null || !filter.getBmine()) {
            // 判断该用户是否有神秘商人管理权限
            EgRole role = userService.mypurview(uid);
            if (role != null && (role.getPurview() & EgPurview.TRADER_MG) == 0) {
                return new ResponseResult<>(ResponseMessage.INADEQUATE_PERMISSIONS);
            }
        }
        return new ResponseResult<>(ResponseMessage.OK, goodsHistoryService.history(filter, user));
    }
}
